package models

import (
	"time"

	"gddgame.cc/galaxy/common"
	. "gddgame.cc/galaxy/common/dsl/db"
	"gddgame.cc/galaxy/utils/orm"
)

var (
	UserModel = orm.NewModel("user", &User{}, nil)
)

func init() {
	AddTable(&Table{
		Model: UserModel,
	})
}

// 跨应用的用户账户，保持统一的登录验证
type User struct {
	Id       int    `json:"id" orm:"auto" sql:"INT"`
	GuestId  string `json:"guest_id" sql:"VARCHAR"`
	Name     string `json:"name" sql:"VARCHAR"`
	Password string `json:"-" hidden:"password" sql:"VARCHAR"`
	Email    string `json:"email" sql:"VARCHAR"`
	Mobile   string `json:"mobile" sql:"VARCHAR"`

	WechatUnionId          string `json:"wechat_union_id" sql:"VARCHAR"`
	FacebookUnionId        string `json:"facebook_union_id" sql:"VARCHAR"`
	QQUnionId              string `json:"qq_union_id" sql:"VARCHAR"`
	AppleGameCenterUnionId string `json:"apple_game_center_union_id" sql:"VARCHAR"`
	GoogleGamePlayUnionId  string `json:"google_game_play_union_id" sql:"VARCHAR"`
	MiGameUnionId          string `json:"mi_game_union_id" sql:"VARCHAR"`
	HuaweiUnionId          string `json:"huawei_union_id" sql:"VARCHAR"`
	UcUnionId              string `json:"uc_union_id" sql:"VARCHAR"`

	IdCard   string `json:"id_card" sql:"VARCHAR"`
	RealName string `json:"real_name" sql:"VARCHAR"`

	ThirdRealStatus bool `json:"third_real_status" sql:"TINYINT"`
	ThirdRealAge    int  `json:"third_real_age"`
	ThirdIsUnderAge bool `json:"third_is_under_age" sql:"TINYINT"`

	CreateTime *time.Time `json:"create_time" orm:"createTime" sql:"dateTime"`
	UpdateTime *time.Time `json:"update_time" orm:"updateTime" sql:"dateTime"`
	DeleteTime *time.Time `json:"delete_time" orm:"deleteTime" sql:"dateTime"`
}

func (user *User) FormatPassword(password string) string {
	return common.Md5(common.Md5(password) + password)
}
